package com.ezjie.ielts.module_word.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ezjie.ielts.R;
import com.ezjie.ielts.model.Instance;
import com.ezjie.ielts.util.TextUtil;

public class WordFirstStudyDetailAdapter extends BaseAdapter {
	private Context mContext;
	private List<Instance> list;
	private LayoutInflater mInflater;

	private String keyword;

	public WordFirstStudyDetailAdapter(Context context) {
		this.mContext = context;
		this.mInflater = LayoutInflater.from(context);
	}

	public void setList(List<Instance> list) {
		this.list = list;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list == null ? 0 : list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (null == convertView) {

			convertView = LayoutInflater.from(mContext).inflate(R.layout.layout_word_first_study_detail_item, null);
			holder = new ViewHolder();
			holder.tv_origin = (TextView) convertView.findViewById(R.id.tv_origin);
			holder.tv_translation = (TextView) convertView.findViewById(R.id.tv_translation);
			holder.iv_speak = (ImageView) convertView.findViewById(R.id.iv_speak);

			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		Instance instance = list.get(position);
		holder.iv_speak.setTag(position);
		if (instance != null) {
			String origin = instance.getOrigin();
			holder.tv_origin.setText(TextUtil.transferBoldWhiteWord(keyword, origin));
			holder.tv_translation.setText(instance.getTranslation() + "");
		}

		return convertView;
	}

	class ViewHolder {
		TextView tv_origin;
		TextView tv_translation;
		ImageView iv_speak;
	}

}
